package com.cjh.springcloud.controller;

import com.cjh.springcloud.pojo.Emp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @Author cjh
 * @Date 2020/12/3 17:53
 * @Version 1.0
 */
@RestController
@RequestMapping("/consumer")
public class EmpConsumerController {

    // Ribbon 这里的地址应该是一个变量，通过服务名来访问
//    private static final String REST_URL_PREFIX = "http://localhost:8001";
    private static final String REST_URL_PREFIX = "http://SPRINGCLOUD-PROVIDER-EMP";

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/get/{empId}")
    public Emp get(@PathVariable("empId") Integer empId) {

        return restTemplate.getForObject(REST_URL_PREFIX + "/provider/queryOne/" + empId, Emp.class);
    }

    @GetMapping("/getAll")
    public List<Emp> get() {

        return restTemplate.getForObject(REST_URL_PREFIX + "/provider/queryAll/", List.class);
    }
}
